﻿Imports System
Imports System.ComponentModel
Imports System.Drawing.Design
Imports System.Workflow.ComponentModel

Namespace System.Workflow.ComponentModel.Design
    <ProvideProperty("BaseActivityType", GetType(Activity))> _
    Friend NotInheritable Class CustomActivityPropertyExtender
        Implements IExtenderProvider
        ' Methods
        <DesignOnly(True), Editor(GetType(TypeBrowserEditor), GetType(UITypeEditor)), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), SRDisplayName("BaseActivityType"), SRCategory("Activity"), TypeFilterProvider(GetType(BaseClassTypeFilterProvider)), DefaultValue("System.Workflow.ComponentModel.Sequence"), SRDescription("CustomActivityBaseTypeDesc")> _
        Public Function GetBaseActivityType(ByVal activity As Activity) As String
            Return activity.GetType.FullName
        End Function

        Public Sub SetBaseActivityType(ByVal activity As Activity, ByVal baseActivityTypeName As String)
            CustomActivityDesignerHelper.SetBaseTypeName(baseActivityTypeName, activity.Site)
        End Sub

        Private Function System.ComponentModel.IExtenderProvider.CanExtend(ByVal extendee As Object) As Boolean Implements IExtenderProvider.CanExtend
            Dim flag As Boolean = False
            Dim activity As Activity = [TryCast](extendee,Activity)
            If (((Not activity Is Nothing) AndAlso (Not activity.Site Is Nothing)) AndAlso (activity Is Helpers.GetRootActivity(activity))) Then
                Dim designer As ActivityDesigner = ActivityDesigner.GetDesigner(activity)
                If ((Not designer Is Nothing) AndAlso (designer.ParentDesigner Is Nothing)) Then
                    flag = True
                End If
            End If
            Return flag
        End Function

    End Class
End Namespace

